﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int playscore = 0;
            int compsocre = 0;
            int count = 0;

            Game g1 = new Game("剪刀");
            Game g2 = new Game("石头");
            Game g3 = new Game("布");
            List<Game> games = new List<Game>() { g1, g2, g3 };

            Competitor competitor1 = new Competitor();
            Gameplayer gameplayer1 = new Gameplayer();

            Console.WriteLine("请选择对方角色<1.刘备 2.孙权 3.曹操>");
            int key2 = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入你的姓名");
            gameplayer1.Name = Console.ReadLine();

            switch (key2)
            {
                case 1:
                    competitor1.Name = "刘备";
                    break;
                case 2:
                    competitor1.Name = "孙权";
                    break;
                case 3:
                    competitor1.Name = "曹操";
                    break;
            }
            Console.WriteLine("开始游戏吗?<Y/N>");
            string key = Console.ReadLine();
            while (true)
            {
                while (key.Equals("y", StringComparison.OrdinalIgnoreCase))
                {

                    Console.WriteLine($"{gameplayer1.Name} VS {competitor1.Name}");

                    Random ran = new Random();
                    int a = ran.Next(0, 3);
                    Console.WriteLine("请出拳:1.剪刀，2.石头，3.布（请输入相应数字：）");
                    int key1 = int.Parse(Console.ReadLine());
                    switch (key1)
                    {
                        case 1:
                            if (!(key1 - 1 == a))
                            {
                                Console.WriteLine($"{gameplayer1.Name}:出：{games[key1 - 1]}\n{competitor1.Name}:出：{games[a]}");

                                if (games[a].A.Equals("石头"))
                                {
                                    count++;
                                    compsocre++;
                                    Console.WriteLine($"笨蛋 ，{gameplayer1.Name}输了");
                                }
                                if (games[a].A.Equals("布"))
                                {
                                    count++;
                                    playscore++;
                                    Console.WriteLine($"恭喜 ，{gameplayer1.Name}赢了");
                                }
                            }
                            else
                            {
                                count++;
                                Console.WriteLine($"{gameplayer1.Name}:出：{games[key1 - 1]}\n{competitor1.Name}:出：{games[a]}");

                                Console.WriteLine("平局");
                            }

                            break;
                        case 2:
                            if (!(key1 - 1 == a))
                            {
                                if (games[a].A.Equals("布"))
                                {
                                    count++;
                                    compsocre++;
                                    Console.WriteLine($"笨蛋 ，{gameplayer1.Name}输了");
                                }
                                if (games[a].A.Equals("剪刀"))
                                {
                                    count++;
                                    playscore++;
                                    Console.WriteLine($"恭喜 ，{gameplayer1.Name}赢了");
                                }
                            }
                            else
                            {
                                count++;
                                Console.WriteLine($"{gameplayer1.Name}:出：{games[key1 - 1]}\n{competitor1.Name}:出：{games[a]}");

                                Console.WriteLine("平局");
                            }
                            break;
                        case 3:

                            if (!(key1 - 1 == a))
                            {
                                if (games[a].A.Equals("剪刀"))
                                {
                                    count++;
                                    compsocre++;
                                    Console.WriteLine($"笨蛋 ，{gameplayer1.Name}输了");
                                }
                                if (games[a].A.Equals("石头"))
                                {
                                    count++;
                                    playscore++;
                                    Console.WriteLine($"恭喜 ，{gameplayer1.Name}赢了");
                                }
                            }
                            else
                            {
                                count++;
                                Console.WriteLine($"{gameplayer1.Name}:出：{games[key1 - 1]}\n{competitor1.Name}:出：{games[a]}");

                                Console.WriteLine("平局");
                            }
                            break;
                    }

                    Console.WriteLine("是否进行下一轮：<Y/N>");
                    string b = Console.ReadLine();
                    if (b == "Y" || b == "y")
                    {
                    }
                    else if (b == "n" || b == "N")
                    {
                        Console.WriteLine($"{gameplayer1.Name} VS {competitor1.Name}");
                        Console.WriteLine($"对战次数：{count}\n\n姓名\t得分\n{gameplayer1.Name}\t{playscore}\n{competitor1.Name}\t{compsocre}");
                        if (playscore > compsocre)
                        {
                            Console.WriteLine($"结果：{gameplayer1.Name}赢了,{competitor1.Name}输了");
                        }
                        else if(playscore<compsocre)
                        {
                            Console.WriteLine($"结果：{competitor1.Name}赢了,{gameplayer1.Name}输了");
                        }
                        else
                        {
                            Console.WriteLine($"结果：平局");
                        }
                        break;
                    }

                    if (key == "n" || key == "N")
                    {
                        Console.WriteLine("End...");
                        break;
                    }
                }
                Console.WriteLine("是否要进行下一局：<Y/N>");
                key = Console.ReadLine();
                if (key.Equals("n",StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("系统退出！！！");
                }
            } 
        }
    }
    class Competitor
    {
        private string name;

        public string Name { get => name; set => name = value; }
    }
    class Gameplayer
    {
        private string name;

        public string Name { get => name; set => name = value; }
    }
    class Game
    {
        private string a;

        public Game(string a)
        {
            this.a = a;
        }

        public string A { get => a; set => a = value; }
        public override string ToString()
        {
            return $"{a}";
        }
    }

}
